﻿using EFCore3.Entity.树形结构;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EFCore3.EntityConfig
{
    public class MenuConfig : IEntityTypeConfiguration<Menu>
    {
        public void Configure(EntityTypeBuilder<Menu> builder)
        {
           builder.ToTable("T_Menu").HasKey(x => x.Id);
           builder.HasOne(p => p.Parent).WithMany(p=>p.Childs).HasForeignKey(p => p.ParentId).OnDelete(DeleteBehavior.Restrict);
        }
    }
}
